********************************************************************************
clear all
set more off
capture log close

********************************************************************************
** File paths
** Set the current directory to the same folder where the code is

global input "../input" 
global output "../output" 
global temp "../temp"

********************************************************************************
* Start log, save it into temp folder
log using "$temp/power_analysis_graphs", replace

********************************************************************************
** Figures
********************************************************************************
import delimited using $temp/temp_length_1_1_1.csv, clear colrange(2:)
gen vEffectSize  = v1 - 100
rename v2 vRejectP10
rename v3 vRejectP5
collapse (mean) vRejectP10 vRejectP5, by(vEffectSize)
list
twoway scatter vRejectP10 vRejectP5 vEffectSize if vEffectSize >=5, connect(line line) graphregion(fcolor(gs16)) scheme(s2mono) lcolor(gs0 red) mcolor(gs0 red) lpattern(dash solid) xlabel(, labsize(medlarge)) ylabel(0(0.2)1, labsize(medlarge)) ytitle("Power" , size(medlarge)) xtitle("Effect size (%)",size(medlarge)) legend(label(1 "{&alpha}= 0.1") label(2 "{&alpha}= 0.05") size(medlarge)) 
graph export $output/gPower_Length_240.pdf, replace

import delimited using $temp/temp_users_1_1_1.csv, clear colrange(2:)
rename v1 vEffectSize 
rename v2 vRejectP10
rename v3 vRejectP5
tabulate vEffectSize
collapse (mean) vRejectP10 vRejectP5, by(vEffectSize)
list 
twoway scatter vRejectP10 vRejectP5 vEffectSize, connect(line line) graphregion(fcolor(gs16)) scheme(s2mono) lcolor(gs0 red) mcolor(gs0 red) lpattern(dash solid) xlabel(, labsize(medlarge)) ylabel(0(0.2)1, labsize(medlarge)) ytitle("Power" , size(medlarge)) xtitle("Effect size (monthly number of users)",size(medlarge)) legend(label(1 "{&alpha}= 0.1") label(2 "{&alpha}= 0.05") size(medlarge)) 
graph export $output/gPower_Users_240.pdf, replace

import delimited using $temp/temp_length_1_1_0.csv, clear colrange(2:)
gen vEffectSize  = v1 - 100
rename v2 vRejectP10
rename v3 vRejectP5
collapse (mean) vRejectP10 vRejectP5, by(vEffectSize)
list 
twoway scatter vRejectP10 vRejectP5 vEffectSize if vEffectSize >=5 , connect(line line) graphregion(fcolor(gs16)) scheme(s2mono) lcolor(gs0 red) mcolor(gs0 red) lpattern(dash solid) xlabel(, labsize(medlarge)) ylabel(0(0.2)1, labsize(medlarge)) ytitle("Power" , size(medlarge)) xtitle("Effect size (%)",size(medlarge)) legend(label(1 "{&alpha}= 0.1") label(2 "{&alpha}= 0.05") size(medlarge)) 
graph export $output/gPower_Length_180.pdf, replace

import delimited using $temp/temp_users_1_1_0.csv, clear colrange(2:)
rename v1 vEffectSize 
rename v2 vRejectP10
rename v3 vRejectP5
tabulate vEffectSize
collapse (mean) vRejectP10 vRejectP5, by(vEffectSize)
list 
twoway scatter vRejectP10 vRejectP5 vEffectSize, connect(line line) graphregion(fcolor(gs16)) scheme(s2mono) lcolor(gs0 red) mcolor(gs0 red) lpattern(dash solid) xlabel(, labsize(medlarge)) ylabel(0(0.2)1, labsize(medlarge)) ytitle("Power" , size(medlarge)) xtitle("Effect size (monthly number of users)",size(medlarge)) legend(label(1 "{&alpha}= 0.1") label(2 "{&alpha}= 0.05") size(medlarge)) 
graph export $output/gPower_Users_180.pdf, replace

*******************************************************************************
log close
clear
